package com.rizzo.back.util.search;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.de.GermanAnalyzer;
import org.apache.lucene.analysis.fr.FrenchAnalyzer;
import org.apache.lucene.analysis.nl.DutchAnalyzer;
import org.apache.lucene.analysis.shingle.ShingleAnalyzerWrapper;
import org.apache.lucene.analysis.snowball.SnowballAnalyzer;

/**
 * TODO Insert JavaDoc!
 */
public enum AnalyzerType {

    DUTCH("nl", DutchAnalyzer.class),
    FRENCH("fr", FrenchAnalyzer.class),
    ENGLISH("en", SimpleAnalyzer.class),
    GERMAN("de", GermanAnalyzer.class),
    SNOWBALL("sb", SnowballAnalyzer.class),
    SHINGLE("sh", ShingleAnalyzerWrapper.class);

    private String mnemonic;

    private Class clazz;

    /**
     * Constructor AnalyzerType creates a new AnalyzerType instance.
     *
     * @param mnemonic of type String
     * @param clazz of type Class
     */
    AnalyzerType(String mnemonic, Class clazz) {
        this.mnemonic = mnemonic;
        this.clazz = clazz;
    }

    /**
     * Method getMnemonic returns the mnemonic of this AnalyzerType object.
     *
     * @return the mnemonic (type String) of this AnalyzerType object.
     */
    public String getMnemonic() {
        return mnemonic;
    }

    /**
     * Method getClazz returns the clazz of this AnalyzerType object.
     *
     * @return the clazz (type Class) of this AnalyzerType object.
     */
    public Class getClazz() {
        return clazz;
    }

    /**
     * Method getInstantiation returns the instantiation of this AnalyzerType object.
     *
     * @return the instantiation (type Object) of this AnalyzerType object.
     * @throws ClassNotFoundException when
     * @throws IllegalAccessException when
     * @throws InstantiationException when
     */
    public Analyzer getInstantiation() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        return (Analyzer) Class.forName(this.getClazz().getName()).newInstance();
    }
}
